package com.cndw.kungfu.model;

import java.io.Serializable;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

import com.cndw.kungfu.core.CacheDataBase;
import com.cndw.kungfu.core.CacheDataKey;
import com.cndw.kungfu.model.pvp.camp.CampRecord;
import com.cndw.kungfu.model.pvp.camp.CampWarPlayer;
/**
 * pvp临时数据入口,不是很重要的数据,但不能估算大小
 * @author fantadust [9677889@qq.com]
 * @date 2012-8-13 下午3:05:38
 */
public class PvpCommSerialize extends CacheDataBase implements Serializable {

	private static final long serialVersionUID = 9677889L;

	private static PvpCommSerialize instance = null;
	/**
	 * 门派战的历史记录
	 */
	private Map<Long, CampRecord> campRecordMap = new ConcurrentHashMap<Long, CampRecord>();

	private PvpCommSerialize() {
	}

	@Override
	public String getKey() {
		return CacheDataKey.PvpCommSerialize;
	}

	public static PvpCommSerialize getInstance() {
		if (instance == null) {
			synchronized (PvpCommSerialize.class) {
				if (instance == null) {
					CacheDataBase cacheData = Context.getSysServer().initCacheData(CacheDataKey.PvpCommSerialize);
					if (cacheData != null && cacheData instanceof PvpCommSerialize) {
						instance = (PvpCommSerialize) cacheData;
					}
					if (instance == null) {
						instance = new PvpCommSerialize();
					}
					if (instance.getSyncDBTime() == 0) {
						instance.commitSync();
					}
				}
			}

		}
		return instance;

	}
	
	
	
	public CampRecord getCampRecord(long uid){
		return campRecordMap.get(uid);
	}
	
	public void campRecordChk(CampWarPlayer e){
		if (!campRecordMap.containsKey(e.getId()) || campRecordMap.get(e.getId()).getStreak() < e.getStreak()) {
			campRecordMap.put(e.getId(), e.toRecord());
		}	
	}
	

}
